unit Unit1;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,  Variants, ComObj, Forms,
  Controls, Graphics, Dialogs, ExtCtrls, StdCtrls;

type

  { TForm1 }

  TForm1 = class(TForm)
    Button1: TButton;
    Image1: TImage;
    Label1: TLabel;
    Label2: TLabel;
    Timer1: TTimer;
    procedure Button1Click(Sender: TObject);
    procedure Timer1Timer(Sender: TObject);
  private

  public

  end;

var
  Form1: TForm1;

implementation

uses MMSystem;

{$R *.lfm}

{ TForm1 }

procedure TForm1.Timer1Timer(Sender: TObject);
var
  x, y: integer;
  sj: TdateTime;
  hour, min, sec, msec: word;
  a: olevariant;
  s: string;
const
  pi = 3.1415926;

begin
  refresh;
  sj := time;
  DecodeTime(sj, hour, min, sec, msec);
  Label2.Caption := TimeToStr(sj);
  //画秒针
  x := round(210 * cos(2 * pi - (sec - 15) * pi / 30)) + 250;
  y := round(210 * sin(2 * pi + (sec - 15) * pi / 30)) + 250;

  with canvas do
  begin
    pen.Width := 1;
    pen.Color := clRed;
    moveto(250, 250);
    LineTo(x, y);
  end;
  //画分针
  x := round(180 * cos(2 * pi - ((min + sec / 60) - 15) * pi / 30)) + 250;
  y := round(180 * sin(2 * pi + ((min + sec / 60) - 15) * pi / 30)) + 250;
  with canvas do
  begin
    pen.Width := 2;
    pen.Color := clBlue;
    moveto(250, 250);
    LineTo(x, y);
  end;

  //画时针
  x := round(130 * cos(2 * pi - ((hour + min / 60) - 15) * pi / 6)) + 250;
  y := round(130 * sin(2 * pi + ((hour + min / 60) - 15) * pi / 6)) + 250;

  with canvas do
  begin
    pen.Width := 4;
    pen.Color := clBlue;
    moveto(250, 250);
    LineTo(x, y);
  end;
  //整点报时
  if (min = 0) and (sec = 0) then
  begin
    sndPlaySound(PChar('zd.wav'), SND_ASYNC);
    a:=createoleobject('SAPI.SpVoice');
    s:='现在是北京时间'+inttostr(hour)+'点整';
    a.speak(s);
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  s:string;
  a:olevariant;
  sj:TDateTime;
  hour,min,sec,msec:word;
begin
  sj:=time;
  DecodeTime(sj, hour, min, sec, msec);
  s:='现在是北京时间'+inttostr(hour)+'点 '+inttostr(min)+'分' ;
  a:=createoleobject('SAPI.SpVoice');
  a.speak(s);
end;

end.
